package org.jeecg.chase.common.supper.process;

import org.springframework.core.Ordered;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @author leikai
 * @version 1.0
 * @description:
 * @date 2021/08/04/0004 17:36
 */
public class CommonProcess implements Ordered {

    /**
     * ID  只有配置在数据库中的前后置处理逻辑的id才有值。通过java注解配置在实体或query上的前后置处理逻辑的id都为null
     */
    private String id;

    /**
     * 顺序
     */
    private Integer order = Integer.MAX_VALUE;

    /**
     * 脚本执行的条件表达式
     */
    private String conditionExpression;

    /**
     * 处理的Service的bean的name
     */
    private String service;

    /**
     * 处置方法的name
     */
    private String method;

    /**
     * 处理的Service
     */
    private Object serviceObject;

    /**
     * 处置方法
     */
    private Method methodObject;

    /**
     * 脚本的参数类型
     */
    private Class<?>[] paramTypes;

    /**
     * 第一个参数是否是集合
     */
    private Boolean firstParamTypeIsIterable = false;

    /**
     * 脚本参数
     */
    private List<Object> paramList = new ArrayList<Object>();

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(service);
        builder.append(".");
        builder.append(method);
        return builder.toString();
    }

    @Override
    public int getOrder() {
        if (this.order != null) {
            return this.order;
        }
        return Ordered.LOWEST_PRECEDENCE;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public String getConditionExpression() {
        return conditionExpression;
    }

    public void setConditionExpression(String conditionExpression) {
        this.conditionExpression = conditionExpression;
    }

    public Boolean getFirstParamTypeIsIterable() {
        return firstParamTypeIsIterable;
    }

    public void setFirstParamTypeIsIterable(Boolean firstParamTypeIsIterable) {
        this.firstParamTypeIsIterable = firstParamTypeIsIterable;
    }

    public List<Object> getParamList() {
        return paramList;
    }

    public void setParamList(List<Object> paramList) {
        this.paramList = paramList;
    }

    public Class<?>[] getParamTypes() {
        return paramTypes;
    }

    public void setParamTypes(Class<?>[] paramTypes) {
        this.paramTypes = paramTypes;
    }

    public Object getServiceObject() {
        return serviceObject;
    }

    public void setServiceObject(Object serviceObject) {
        this.serviceObject = serviceObject;
    }

    public String getService() {
        return service;
    }

    public void setService(String service) {
        this.service = service;
    }

    public Method getMethodObject() {
        return methodObject;
    }

    public void setMethodObject(Method methodObject) {
        this.methodObject = methodObject;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
